package com.lc.dmd.controller;

import com.lc.dmd.entity.Food;
import com.lc.dmd.entity.vo.DataVo;
import com.lc.dmd.service.ds1.StudentService;
import com.lc.dmd.service.ds2.FoodService;
import com.study.common.ano.DataSourceAnnotation;
import com.study.common.enums.DataSourceEnum;
import com.study.common.res.ApiResult;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @description: some desc
 * @author: LChuang
 * @date: 2023/9/6 15:34
 */
@RestController
@RequestMapping("/test")
@RequiredArgsConstructor
public class TestController {

    private final StudentService studentService;

    private final FoodService foodService;

    @GetMapping("/allData")
    public ApiResult getAllData(){
        DataVo vo = studentService.getAllData();
        return ApiResult.success(vo);
    }


    @GetMapping("/foodList")
    @DataSourceAnnotation(value = DataSourceEnum.DS2)
    public ApiResult getFoodList(){
        // food表在local_db2中，需要在接口上使用注解切换数据源
        List<Food> list = foodService.list();
        return ApiResult.success(list);
    }
}
